<template>
   <div class="login">
    <div class="loginbox">
    <div class="imgbox">
     <img src="../assets/logo.png" alt="">
    </div>
     <div class="login-form">
      <el-form ref="form" :model="form" label-width="80px">
  <el-form-item label="用户名">
    <el-input v-model="form.username"></el-input>
  </el-form-item>
   <el-form-item label="密码">
    <el-input v-model="form.password"></el-input>
  </el-form-item>
      </el-form>
  <div class="bo">
  <el-button type="primary" @click="loginFn">登录</el-button>
   <el-button>重置</el-button>
  </div>
     </div>
    </div>
   </div>
</template>
<script>
import { login } from "@/http/user.js";
export default {
  data() {
    return {
      form: {
        username: "admin",
        password: "123456"
      }
    };
  },
  methods: {
    async loginFn() {
      let { username, password } = this.form;
      let res = await login({ username, password });
    //   console.log(res);
      if (res.meta.status == 200) {
        localStorage.setItem("token", res.data.token);
        this.$message({
          message: "恭喜你，登录成功",
          type: "success"
        });
        this.$router.push("/home");
      } else {
        alert(res.meta.msg);
      }
    }
  }
};
</script>
<style lang="scss">
.login {
  height: 100vh;
  background: #2b4b6b;
  position: relative;
}
.loginbox {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 450px;
  height: 304px;
  background-color: #fff;
  position: absolute;
}
.imgbox {
  background: #fff;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 10px #ddd;
  border-radius: 50%;
  padding: 10px;
  img {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background-color: #efefef;
  }
}
.login-form {
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>


